import TJavaLib.TString;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.util.Date;

public class TTime {
	public static long systemTime() { 
		return Calendar.getInstance().getTimeInMillis(); 
	}
	
	public static String dateTimeOf(long t) {
		DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    return formatter.format(new Date(t));
	}
	
	public static long timeInMilis(String date, String time) {
		TString sd = new TString(date, '.');
		TString st = new TString(time, ':');
		Calendar c = Calendar.getInstance();
		int day = Integer.valueOf(sd.getStrAt(0));
		int month = Integer.valueOf(sd.getStrAt(1))-1;
		int year = Integer.valueOf(sd.getStrAt(2));
		int h = Integer.valueOf(st.getStrAt(0));
		int m = Integer.valueOf(st.getStrAt(1));
		int s = Integer.valueOf(st.getStrAt(2));
		c.set(year, month, day, h, m, s);
    return c.getTimeInMillis();
	}
	
	public static String timeOf(long t) {
		DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
		return formatter.format(new Date(t));
	}
	
	public static long timeInMilis(String time) {
		long h = 0;
		long m = 0;
		long s = 0;
		TString st = new TString(time, ':');
		if (st.len() == 3) {
			h = Long.valueOf(st.getStrAt(0));
			m = Long.valueOf(st.getStrAt(1));
			s = Long.valueOf(st.getStrAt(2));
		} else if (st.len() == 2) {
			m = Long.valueOf(st.getStrAt(0));
			s = Long.valueOf(st.getStrAt(1));
		} else if (st.len() == 1) {
			s = Long.valueOf(time);
		}
		
		return h*60*60*1000 + m*60*1000 + s*1000;
	}
	
	public static String dateOf(long t) {
		DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
		return formatter.format(new Date(t));
	}
	
	public static int hourOf(long t) {
		Calendar c = Calendar.getInstance();
    c.setTimeInMillis(t);
    return c.get(Calendar.HOUR_OF_DAY);
	}
}
